package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;


@Getter@Setter
public class Travel extends BaseDomain{

    public static final Integer STATE_NORMAL=0;//草稿
    public static final Integer STATE_REJECT=-1;//拒绝
    public static final Integer STATE_WAIT=1;//待发布,保存了
    public static final Integer STATE_RELEASE=2;//发布

    private String title;

    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;

    private String perExpends;

    private Integer days;

    private Integer person;

    private User author;

    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date releaseTime;

    private Boolean isPublic=false;

    private Region place;

    private String coverUrl;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date lastUpdateTime;

    private Integer state=STATE_NORMAL;

    private TravelContent travelContent;//关联文章对象

    public String getStateName(){
        String msg="";
        if(this.state==STATE_NORMAL){
            msg="草稿";
        }else if(this.state==STATE_REJECT){
            msg="拒绝";
        }else if(this.state==STATE_WAIT){
            msg="待发布";
        }else if(this.state==STATE_RELEASE){
            msg="已发布";
        }
        return msg;
    }

    public String getPersonName(){
        String msg="一个人的旅行";
        if(this.person==2){
            msg="和父母";
        }else if(this.person==3){
            msg="和朋友";
        }else if(this.person==4){
            msg="和同事";
        }else if(this.person==5){
            msg="和爱人";
        }else if(this.person==6){
            msg="和其他";
        }
        return msg;
    }
    public String getJson(){
        HashMap map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        return JSONUtil.toJSONString(map);
    }

}